package com.action;
import com.dto.UserAuthDTO;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserAuthService;

public class UserSignInAction extends BaseAction
{
	String userName;
	String password;
	String operation;
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getOperation() {
		return operation;
	}
	public void setOperation(String operation) {
		this.operation = operation;
	}
	
	@Override
	public String execute() throws Exception 
	{
		UserAuthDTO dto = new UserAuthDTO();
		UserAuthService service = new UserAuthService();

		if("Signin".equalsIgnoreCase(operation))
		{
			dto.setUserName(userName);
			dto.setPassword(password);
			dto = service.signIn(dto);
			if(dto != null)
			{
				session.setAttribute("user", dto); 
				return "SignIn";
			}
			else
			{
				addActionError("The username or password you entered is incorrect.");
				return "error";
			}
		}
		return SUCCESS;
	}
	
	@Override
	public String input() throws Exception 
	{
		return SUCCESS;
	}
}
